Skip to content

fix: struct constructors on napi; boxed struct values on both engines - #28

Merged
triniwiz merged 2 commits into
mainfrom
fix/napi-struct-ctor-propertyvalue
Oct 17, 2026
Merged

triniwiz merged 2 commits into
mainfrom
fix/napi-struct-ctor-propertyvalue

Conversation

@triniwiz

Copy link
Copy Markdown
Member

Stacked on #26 (base perf/struct-values-namespaces). GitHub retargets it to main when #26 merges.

Summary

Three struct gaps, fixed on both engines where they applied.

1. Struct constructors on napi

napi namespaces returned undefined for struct types (Windows.Foundation.Rect). They now resolve to a constructor:

new Rect({ X: 1, Y: 2, Width: 3, Height: 4 }) // named
new Rect(5, 6, 7, 8)                         // positional
new Rect()                                   // all zero
new Rect({ X: 1 })                           // missing fields zero
new Duration({ TimeSpan: { Duration: 5 }, Type: 1 }) // nested

The result is the same plain object a struct return gives. It's built by serializing through the struct's byte layout and reading back, so values match exactly what native receives.

2. Boxed structs (IReference<Point> etc.)

An IPropertyValue holding a Point, Size, Rect, TimeSpan or DateTime used to come back as an empty wrapper: {} on napi, { handle } on classic. It now unboxes to a struct value, e.g. PropertyValue.CreatePoint({X:1.5,Y:2.5}) gives { X: 1.5, Y: 2.5 }, and so does PropertySet.Lookup for a stored Point.

To keep the "create a value and store it in settings" pattern working, a plain object passed to an Object parameter is now boxed by its shape. {X,Y} becomes a Point, {Width,Height} a Size, {X,Y,Width,Height} a Rect, {Duration} a TimeSpan, and {UniversalTime} a DateTime. These are the only struct types IPropertyValue supports, and their field names don't overlap. So propertySet.Insert('p', { X: 1, Y: 2 }) now works directly.

3. Serializer fixes (both engines)

Also checked

  • By-value small structs are fine on both engines. new Windows.UI.Input.Inking.InkPoint({X:3,Y:4}, 0.5).Position round-trips (Point, 8 bytes, passed in a register).
  • Test fix pushed to perf: plain struct values and cached namespace lookups (classic) #26. Its round-trip test used TimedTextStyle.Padding, which doesn't exist (that class has no Padding), so it only round-tripped a JS property. It now uses TimedTextRegion.Padding and asserts no own property was created.

Testing

  • Classic: new integration-tests/tests/boxed_structs.rs; all 18 integration test targets pass; runtime unit tests show the same 11 known failures as main.
  • napi: npm test passes 417/417, including 11 new checks in struct-test.js.

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4c89c0b7-61b6-4be4-a36d-2da86c3074a3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Base automatically changed from perf/struct-values-namespaces to main October 17, 2026 08:21
@triniwiz
triniwiz merged commit b02d1d7 into main Oct 17, 2026
4 checks passed
@triniwiz
triniwiz deleted the fix/napi-struct-ctor-propertyvalue branch October 17, 2026 08:21
- napi namespaces resolve struct types to a constructor
  (`new Rect({...})`, `new Rect(x, y, w, h)`, `new Rect()`), returning
  the same plain object a struct return gives
- IPropertyValue holding Point/Size/Rect/TimeSpan/DateTime unboxes to
  a struct value instead of an empty wrapper
- plain objects shaped like those five types box back when passed to
  an Object parameter (PropertySet.Insert, settings values)
- missing struct fields serialize as zero instead of NaN
- napi struct String fields are written
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant